
layui.use(['laytpl','element', 'form', 'carousel', 'layer', 'table','laydate'], function() {
	var element = layui.element;
	var carousel = layui.carousel;
	var form = layui.form;
	var laytpl = layui.laytpl;
	var layer = layui.layer;
	var $ = layui.$
	var table = layui.table;
	var laydate = layui.laydate;
	var studentNo;
	var paperId;

	//取sessionStorage里面的userKey
	var teacherInfo = document.getElementById("teacherInfo").innerHTML;
	var teacherList = document.getElementById("teacherList").innerHTML;
	var userKey = JSON.parse(sessionStorage.getItem("userKey"));
	console.log(userKey)
	if(userKey) {
		//如果存在,则说明登录过,先比对过期时间
		var delayTime = userKey.delayTime
		var nowTime = new Date().getTime()
		if(nowTime < delayTime) {
			//登录未失效
			laytpl(teacherInfo).render(userKey, function(html) {
				$("#teacherInfoView").html(html)
				element.render()
				$.ajax({
					type: "get",
					url: "http://localhost:8888/application/getApplicationByTeacherId",
					data:{'teacherId':userKey.teacherId},
					success: function(data) {
						console.log(data)					
						laytpl(teacherList).render(data, function(html) {
							$("#studentListView").html(html)
							element.render()
						})	
					}
				});
			})
		}
	}


	
	layui.define(function(exports) {
		//do something
	
		exports('application', function(id) {
		
			layui.layer.confirm('您确定要在此日预约？', {
				btn: ['是的', '再想想'] //按钮
			}, function() {
				var userKey = JSON.parse(sessionStorage.getItem("userKey"));
				$.ajax({
					url: "http://localhost:8888/application/approve",
					data: {
						"id": id						
					},
					type: "post",
					success: function(data) {
						console.log(data)
						if(data.code == 0) {
							layui.layer.msg("成功,请按时赴约")
						} else {
							layui.layer.msg("回复失败,请确认")
						}
					},
					error: function() {
						layui.layer.msg("回复失败")
					}
				})
				
			},function(){
				layer.msg("...")
			});
			
		});
	
	});
})
//预约老师

//退出方法
function logout() {
	sessionStorage.clear();
	window.history.href = '../login.html'
}